home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / ViewIt™ 2.24 Shareware / FaceWare / FaceWare.rsrc / TEXT_1316_BC6. Scrollable Lists.txt < prev    next >
Text File  |  1994-04-10  |  10KB  |  89 lines

  1. Scrollable Lists
  2.   Scrollable list controls must be of type "List or Menu", have solid bodies, and be linked to an STR# resource.  The STR# string list can be created and edited with ResEdit, and then optionally manipulated directly by a program using utility commands (see "String Lists" in utility topics).  The current list "value" (= the selected item(s)) is set or read through data linking using SetVal and GetVal.
  3.  
  4. List Items
  5.   The strings in the linked STR# can be either plain text or references to PICT, ICON, SICN, cicn, PAT , PAT#, CURS, acur, or clut resources.  The following string, for example, would display the 4th pattern in PAT# 1000 followed by "Ronald":
  6.   PAT#,1000,4,Ronald
  7. Items can be made inactive by preceding the string with a "-" character:
  8.    -PICT,1005,hello
  9. Note how string elements are separated by commas, and that SICN, PAT#, acur, and clut types require an index value in addition to the resource ID.
  10.  
  11. Options
  12.   The following bit values can be added to VarCode to set various list options:
  13. 2,4,8,16,32,64,128 = "selFlags" defined by List Manager in Volume 4 of Inside Macintosh:
  14.  2 = lNoNilHilite = do not select empty cells
  15.  4 = lUseSense = clicked cell determines action
  16.  8 = lNoRect = (not used by 1-dimensional lists)
  17.  16 = lNoExtend = do not extend Shift selections
  18.  32 = lNoDisjoint = deselect others on mouse click
  19.  64 = lExtendDrag = allow dragging w/o Shift key
  20.  128 = lOnlyOne = one selection at a time
  21. Adding 128 to the VarCode, for example, creates a single-selection type of list, and setting none of the above flags creates a typical multi-selection list.
  22. 256 = display list horizontally (default is vertical)
  23. 512 = do not show vertical or horizontal scroll bar
  24. 1024 = use solid frame rectangle to hilite list items (instead of inverting items)
  25. 2048 (requires data linking) = always update list with current contents of linked STR# resource when SetVal is called, and update STR# with list contents when GetVal is called
  26. 4096 = ignore references to non-text resources in list items and display as text only (do not use this with horizontal lists or option 8192)
  27. 8192 = show text below non-text resource (instead of to its right (vertical) or not at all (horizontal))
  28. 16384 (requires option 2048)= create a separate STR#-type handle from a copy of the linked STR# resource, and use this handle to transfer strings to and from the list on SetVal and GetVal.  The handle to the STR#-like block can be found in cLoData after a call to GetCtl to get control info.
  29.   Horizontal lists have rectangular cells and work best when displaying non-text items.  Vertical lists have cells as wide as the list control and as tall as the list's font, and work best when displaying text items, or text items preceded by small icons.  If the "text below" option is used (8192 in VarCode), then both horizontal and vertical lists have cells that are as tall or wide as the control, with space for displaying text below the non-text resource.
  30.  
  31. STR# Link
  32.   BaseCt uses the Macintosh List Manager to create and display scrollable lists.  The ListHandle for each list can be found in cHiData (after calling GetCtl) and used with List Manager toolbox calls.  WARNING:  We make use of both the "userHandle" and "refCon" fields in the ListHandle, so you won't be able to use these to store program-specific info (use the control's own refCon to store such info, as discussed in "ID/RefCon" in the "Controls" topic of the ViewIt guide).
  33. ‚Ä¢ Fixed Lists
  34.   The strings from the linked STR# are copied into the data handle maintained by the List Manager for each list, meaning that later changes to the STR# list will not affect the displayed list.  This works well in cases where the list is being used to display a fixed set of items.
  35. ‚Ä¢ Dynamic Lists
  36.   In cases where the contents of the list are not fixed, and the list is data-linked to a program variable, then you can use VarCode option 2048 to force the list to "track" the current contents of the linked STR# on calls to GetVal and SetVal.  In this case, the utility command SetStr is typically used to set new strings in the linked STR#, and then SetVal called to update the list in the window.
  37. ‚Ä¢ Multiple Instances
  38.   A limitation of using the "tracking" option is that multiple instances of the same list control (as might occur if opening multiple windows based on the same FWND) are linked to the same STR#, meaning that this STR# resource can't be used to save list info for more than one list control.  A workaround for this limitation is to dynamically allocate an STR#-type block for each such list control (using the SetStr command), and then use DupLst, GetVal, & SetVal to move strings between this STR#-type block and the list control:
  39.   block <-DupLst-> STR# <-Get/SetVal-> control
  40. Since it would be a burden for the programmer to allocate and manage such a block for each control, VarCode option 16384 is available to force BaseCt to allocate such an STR#-type block automatically, and to use the block (instead of the STR# resource) when responding to calls to GetVal and SetVal:
  41.   block <- Get/SetVal -> control
  42. The initial contents of the dynamically allocated block will be a copy of the linked STR# resource, and the block's handle can be found in cLoData after a call to GetCtl to get control info.  This handle can be passed directly to the SetStr and GetStr utility commands to set and get the strings in the block associated with each such list control.
  43.  
  44. Data Linking
  45.   A list control's private "value" is an 8-byte integer that corresponds to the items selected in the list.  For single-selection lists (VarCode contains 128), this value is equal to the number of the currently selected list item.  For multi-selection lists, the list's value is equal to the sum of the bit values corresponding to the selected items in the list.  For example, if the first, third, and fifth items are selected in a multi- selection list, then the list's "value" = 1 + 4 + 16 = 21.  If no items are selected, then the list's value = 0 (for both list types).
  46.   Scrollable lists can be linked to program variables (typically 2, 4 or 8-byte integers - see "Data Links" in the ViewIt Guide for more info on data linking).  On GetVal, an integer value is returned that indicates which items in the list are selected.  On SetVal, the selected list items are updated to reflect the value of the linked program variable.  As described above, you can also have the list contents track the linked STR# resource or a dynamically allocated STR#-type block on GetVal and SetVal.
  47.   The following code, for example, links a 2-byte integer variable named "myInt" to a single-selection list control that is the 3rd control in the 2nd view of the window based on FWND 1005, and then selects the 5th list item:
  48.  FaceIt(nil,GetCtl,1005,0,2,3);
  49.  FaceIt(nil,LnkCtl,ord(cControl), ord(@myInt),2,0);
  50.  ...
  51.  myInt := 5;
  52.  FaceIt(nil,SetVal,1005,0,2,3);
  53.  
  54. Long Lists
  55.   The internal 8-byte (64-bit) integer used to store a list's "value" will be a problem if a multi-selection list has (or can have) more than 64 items.  In this case, the list can be linked to any contiguous block of memory (instead of a single integer) that will be used to get and set selection flags.  This is done by setting the Variable Type of the linked block to 1310 to inform BaseCt that it should treat the data address as the address of a block of bits corresponding to the selection status of items in the list.
  56.   The linked block of bits must be as large or larger than the number of items in the list, otherwise bits beyond the block will get clobbered on GetVal.  The bits in the block should be tested, set, and cleared using the toolbox calls BitTst, BitSet, and BitClr, where the bit offset will be one less than the number of the list item (i.e., zero-based).
  57.   The following code, for example, links a 100-byte block of bits named "myBlock" to a multi-selection list control that is the 3rd control in the 2nd view of the window based on FWND 1005, and then selects the 5th and 6th list items.  Using Pascal,
  58.  myBlock : array [1..50] of integer;
  59.  ...
  60.  for i:= 1 to 50 do
  61.   myBlock[i] := 0;
  62.  FaceIt(nil,GetCtl,1005,0,2,3);
  63.  FaceIt(nil,LnkCtl,ord(cControl), ord(@myBlock),1310,0);
  64.  ...
  65.  BitSet(@myBlock,4);
  66.  BitSet(@myBlock,5);
  67.  FaceIt(nil,SetVal,1005,0,2,3);
  68.  ...
  69. Or, using FORTRAN,
  70.  integer*2 myBlock(50)
  71.  ...
  72.  do i = 1,50
  73.   myBlock(i) = 0
  74.  end do
  75.  call FaceIt(0,GetCtl,1005,0,2,3);
  76.  call FaceIt(0,LnkCtl,cControl,
  77. %loc(myBlock),1310,0);
  78.  ...
  79.  call BitSet(myBlock,%val(4));
  80.  call BitSet(myBlock,%val(5));
  81.  call FaceIt(0,SetVal,1005,0,2,3);
  82.  
  83. Display Tip
  84.   Lists work best if there are no partial cells showing.  To create a list with a whole number of cells: 1) first create a list control that is slightly smaller than the desired size, 2) scroll to the end of the list, and 3) go back into editing mode and expand the list 1 pixel at a time until the last item "jumps" into position.
  85.  
  86. Limitations
  87.   Although scrollable lists act as single Mac controls, the "GetCtl..." and "SetCtl..." toolbox calls do not get or set the list's state since BaseCt makes no use of the control's "contrlValue", "contrlMin", or "contrlMax".
  88.   When using GetVal or SetVal with multi-selection lists linked to integers, the maximum number of list items that can be affected is 64 since the list uses an 8-byte (64-bit) integer to store its "value".  This restriction does not apply to single-selection lists or to the "long lists" described above.
  89.   Scrollable lists currently do not support right or center justification of list contents.  Lists look best with one-pixel frames and no indent.  No support for hand scrolling.